#include<stdio.h>
#include<unistd.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<string.h>
#include<iostream>
#include"protocol.hpp"
int main(){
//建立套接字
//建立连接
//收发数据

  int sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  if(sockfd<0){
    perror("sockfd");
    return 0;
  }
  struct sockaddr_in addr;
  addr.sin_family=AF_INET;
  addr.sin_port=htons(2927);
  addr.sin_addr.s_addr=inet_addr("43.143.149.122");
  int ret=  connect(sockfd,(struct sockaddr*)&addr,sizeof(addr));
  if(ret<0){
    perror("connect");
    return 0;
  }
  while(1){
    struct Request req;
    //char buf[1024]={0};
    printf("please enter data1_:");
    std::cin>>req.data1_;
    printf("please enter  operaed:");
    std::cin>>req.op_;
    printf("please enter data1_:");
    std::cin>>req.data2_;

    //const char* str="i am client ";
    send(sockfd,&req,sizeof(req),0);
    
   // memset(buf,'\0',sizeof(buf));
   struct Response res;
    ssize_t r_size=  recv(sockfd,&res,sizeof(res),0);
    if(r_size<0){
      continue;
    }else if(r_size==0){
    break;
    }else{
      printf("state: %d  resualt is :%d \n",res.reply_status,res.value_);
    }
    sleep(1);
    

  }

  close(sockfd);
  return 0;
}
